<script lang="ts">
import { Swiper, SwiperSlide } from 'swiper/vue';
import { Pagination } from "swiper";
import { ref, onMounted } from 'vue'
import { getSumitomoListData, getSumitomoSellcircleData } from "../api/hhz-Home-Sumitomo";
export default {
    components: {
        Swiper,
        SwiperSlide,
    },
    setup() {
        onMounted(() => {
            document.cookie = "hhz_token=97d82c2a9f34290440bde869cf52be95";
            document.cookie = "visitor_token=vid_a50ef8e60492522f2883f6931c99c81f";
        })
        //推荐圈子
        let SumitomoSellcircle: any = ref(null)
        async function GetSumitomoSellcircleData() {
            let data = await getSumitomoSellcircleData()
            
            //处理数据
            let list:any = []
            let index = parseInt(String(data.data.list.length / 3))
            for (let i = 0; i <= parseInt(String(data.data.list.length / index)) + 1; i++) {
                list.push({
                    ...data.data.list.splice(0, index)
                })
            }
            data.data.list = list
            SumitomoSellcircle.value = data.data

        }
        GetSumitomoSellcircleData()
        // 推荐内容
        let SumitomoListData: any = ref(null)
        async function GetSumitomoDataFun() {
            let data = await getSumitomoListData()
            SumitomoListData.value = data.data.list
        }
        GetSumitomoDataFun()

        //过滤文本
        // const filterStr = (text:string) => {
        //     let reg = /(#[\u4e00-\u9fa5]*\s)/gm
        //     let str = text
        //     let arr = str.split(reg)
        //     arr = arr.filter(item=> item.length > 2);
        //     // console.log(arr);
        //     let newArr:Array<string> = [];
        //     arr.forEach(item=>{
        //         if(item.indexOf('#')!=-1){
        //            newArr.push("<span>" + item + "</span>")
        //         }else{
        //             newArr.push(item);
        //         }
        //     })
        //     // str=newArr.join("\n")
        //     // console.log(str);
            
        //     return str=newArr.join(" ")
        // }
        return {

            SumitomoListData,
            SumitomoSellcircle,
            SumitomoSwiper: [Pagination],
            // filterStr,
        }
    }
}
</script>

<template>
    <div class="Home-Sumitomo">
        <div class="Sumitomo-looking" v-if="SumitomoSellcircle">
            <h1>{{ SumitomoSellcircle.title }}</h1>
            <div class="Sumitomo-lookAll">
                <span>全部</span>
                <van-icon name="arrow" />
            </div>
        </div>
        <div class="Sumitomo-trends">
            <ul>
                <swiper :observer="true" :pagination="true" :modules="SumitomoSwiper" :resistanceRatio=0
                    class="Home-SumitomoSwiper" v-if="SumitomoSellcircle">
                    <swiper-slide v-for="(items, index) in SumitomoSellcircle.list" :key="index">
                        <li class="Sumitomo-List">
                            <ul>
                                <li v-for="item in items" :key="item.num" class="Sumitomo-Item">
                                    <div class="Sumitomo-ItemBox">
                                        <img :src="item.circle_logo">
                                    </div>
                                    <div class="Sumitomo-com">
                                        <h3 class="one-txt-cut">{{ item.circle_name }}</h3>
                                        <p>{{ item.text }}</p>
                                    </div>
                                </li>
                            </ul>
                        </li>
                    </swiper-slide>
                </swiper>
            </ul>
        </div>
        <div class="userarticlelist" v-if="SumitomoListData">
            <div class="userarticle" v-for="(item, index) in SumitomoListData" :key="index">
                <div class="userinfo">
                    <div class="user">
                        <div class="UserIcon">
                            <img :src="item.photo.photo_info.circle_info.circle_logo">
                        </div>
                        <div class="info">
                            <h3>{{ item.photo.photo_info.circle_info.circle_name }}</h3>
                            <p>{{ item.photo.user_info.nick }} 发布</p>
                        </div>
                        <div class="setting">
                            <van-icon name="ellipsis" color="#bbbbbb" />
                        </div>
                    </div>
                </div>
                <div class="articlecontent">
                    <h3>{{ item.photo.photo_info.title }}</h3>
                    
                    <van-text-ellipsis rows="4" :content="item.photo.photo_info.remark" expand-text="展开" />
                </div>
                <!--  -->
                <div class="Trends-ImgBox">
                    <div class="TrendsImg" v-for="index in 3" :key="index">
                        <img :src="item.photo.photo_info.image_list[index - 1]?.thumb_pic_url" @click="">
                    </div>
                    <div class="mask" v-if="item.photo.photo_info.image_list.length - 3 > 0">
                        <div class="num">
                            <p>+{{ item.photo.photo_info.image_list.length - 3 }}</p>
                        </div>
                    </div>
                </div>
                <div class="fotter">
                    <input type="text" placeholder="来评论吧">
                    <van-icon name="like" :size="20" class="likea" />
                    <van-icon :size="20" name="chat" class="like" />
                </div>
            </div>
        </div>

    </div>
</template>
<style lang="scss" scoped>
.Home-Sumitomo::v-deep {
    min-height: 81vh;
    position: relative;

    .Sumitomo-looking {
        background-color: #fff;
        width: 100%;
        padding: 15px;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;

        h1 {
            font-size: 14px;
            font-weight: bold;
        }

        .Sumitomo-lookAll {
            display: flex;
            align-items: center;
            font-size: 12px;
            color: #999999;

            span {
                display: inline-block;
                margin-right: 4px;
            }
        }
    }

    .Sumitomo-trends {
        ul {
            .Home-SumitomoSwiper {
                .swiper-wrapper {
                    height: 200px;
                    background: #fff;

                    .swiper-slide {
                        padding: 0 15px;
                        box-sizing: border-box;
                        background: #fff;

                        .Sumitomo-List {
                            ul {
                                display: flex;
                                align-content: space-between;
                                flex-wrap: wrap;

                                .Sumitomo-Item {
                                    display: flex;
                                    width: 50%;
                                    height: 48px;
                                    align-items: center;
                                    margin-bottom: 10px;

                                    .Sumitomo-ItemBox {
                                        width: 48px;
                                        height: 48px;
                                        flex-shrink: 0;
                                        margin-right: 8px;
                                        border-radius: 4px;
                                        overflow: hidden;
                                    }

                                    .Sumitomo-com {
                                        display: flex;
                                        flex-direction: column;
                                        justify-content: center;
                                        flex: 1;
                                        overflow: hidden;

                                        h3 {
                                            font-size: 14px;
                                            font-weight: bold;
                                            margin-bottom: 4px;
                                        }

                                        p {
                                            font-size: 12px;
                                            color: #999;
                                            transform: scale(0.9);
                                            transform-origin: left;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                .swiper-pagination {
                    .swiper-pagination-bullet {
                        height: 1px;
                        width: 10px;
                    }

                    .swiper-pagination-bullet-active {
                        background: #2aa59a;
                    }
                }
            }
        }
    }

    .userarticlelist {
        padding: 8px 0 50px;
        box-sizing: border-box;

        .userarticle {
            background-color: #fff;
            width: 100%;
            box-sizing: border-box;
            padding: 12px;

            .userinfo {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 16px;

                .user {
                    display: flex;
                    justify-content: space-between;
                    flex: 1;
                    align-items: center;

                    .UserIcon {
                        width: 42px;
                        border-radius: 4px;
                        overflow: hidden;
                    }

                    .info {
                        display: flex;
                        flex-direction: column;
                        margin-left: 10px;
                        flex: 1;

                        h3 {
                            font-weight: bold;
                            font-size: 14px;
                        }

                        p {
                            font-size: 12px;
                            color: #c0c0c2;
                        }

                    }
                }
            }

            .articlecontent {

                h3 {
                    font-size: 14px;
                    font-weight: bold;
                    line-height: 22px;
                }

                p {
                    font-size: 14px;
                    line-height: 22px;
                }
            }

            .Trends-ImgBox {
                margin-top: 10px;
                display: flex;
                justify-content: space-evenly;
                position: relative;

                .mask {
                    position: absolute;
                    height: 108px;
                    width: 108px;
                    background-color: rgba(0, 0, 0, 0.5);
                    right: 6px;
                    border-radius: 5px;

                    .num {

                        p {
                            margin: 40px auto;
                            text-align: center;
                            font-size: 25px;
                            color: #f3f1f1;
                        }
                    }
                }


                img {
                    height: 108px;
                    width: 108px;
                    border-radius: 4px;
                }

            }
        }

        .fotter {
            width: 100%;
            margin-top: 20px;
            background-color: #fff;
            display: flex;
            justify-content: space-between;
            align-items: center;
            z-index: 5;
            box-sizing: border-box;

            input {
                padding: 10px;
                border-radius: 999px;
                outline: none;
                border: 0;
                background-color: #f7f7fb;
            }
        }
    }


}
</style>